<?php
/**
 * TestGuest Version1.0
 * ================================================
 * Copy 2017-2018 zxj
 * Web: http://www.zhaoxiaojie.club
 * ================================================
 * Author: Zxj
 * Date: 17/8/14
 * Time: 下午5:30
 *
 * 接收提交表单的数据
 *
 */
session_start();
include 'common/ini.php';
include 'common/function.inc.php';
include 'common/mysql.inc.php';

   // dd($_POST);

    $username = _guo_lv_ajax($_POST['username']);
    $password = _guo_lv_ajax($_POST['password']);
    $cpassword = _guo_lv_ajax($_POST['cpassword']);
    $code = _guo_lv_ajax($_POST['code']);

    if($password!=$cpassword){

        $ajaxData['status'] = 0;
        $ajaxData['msg'] = '两次密码不一致！';
        echo json_encode($ajaxData);     //必须要echo 不然客户端接收不到数据
        exit();

    }

    if(strtolower($_SESSION['code'])!=strtolower($code)){

        $ajaxData['status'] = 0;
        $ajaxData['msg'] = '验证码不正确！';
        echo json_encode($ajaxData);     //必须要echo 不然客户端接收不到数据
        exit();

    }

        $addtime = date('Y-m-d H:i:s');
        //开始写入数据库
        $logintime = date('Y-m-d H:i:s');

        if(!empty($_POST['touxiang'])){

            $touxiang = $_POST['touxiang'];
        }else{

            $touxiang = 'public/images/topic.jpeg';

        }

        //密码加密
        $password = md5($password);

        $sql = "insert into bbs_pro_user VALUES (null,'$username','$password','$touxiang','$addtime','$logintime')";
        $res = mysql_query($sql);
        if($res){

            //用户的名字放入session
            $_SESSION['pro_username'] = $username;

            $ajaxData['status'] = 1;
            $ajaxData['msg'] = '注册成功！';
            echo json_encode($ajaxData);     //必须要echo 不然客户端接收不到数据
            exit();

        }else{

            $ajaxData['status'] = 0;
            $ajaxData['msg'] = '注册失败！';
            echo json_encode($ajaxData);     //必须要echo 不然客户端接收不到数据
            exit();

        }




?>